import { ProductInfo } from 'src/product-info/entities/product-info.entity';
import { Supplier } from 'src/supplier/entities/supplier.entity';
import { CustomerSimpleChild } from '../../customer-simple-child/entities/customer-simple-child.entity';

import {
  Column,
  CreateDateColumn,
  Entity,
  JoinColumn,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity({ name: 'msb_simple_manage' })
export class Msbmanage {
  @PrimaryGeneratedColumn()
  _Identify: number;

  @Column()
  productcode: string;

  @Column()
  productname: string;

  @Column({ nullable: true })
  cardposition: string;

  @Column({ nullable: true })
  pieceposition: string;

  @Column({ nullable: true })
  simpleposition: string;

  @Column()
  productuniquecode: string;

  @Column({ type: 'nvarchar', length: 50 }) // 定义为nvarchar，和simpleid匹配
  msbmanageidcode: string;

  @CreateDateColumn({ type: 'timestamp' })
  time: Date;

  @Column({ type: 'int', nullable: true })
  cardcount: number;

  @Column({ type: 'int', nullable: true })
  simplecount: number;

  @Column({ nullable: true })
  quoteid: string;

  @Column()
  category: string;

  @Column({ nullable: true })
  remark: string;

  @Column({ nullable: true })
  remarkdetail: string;

  @Column({ type: 'int', nullable: true })
  articleid: number;

  @Column({ nullable: true })
  scancode: string;

  @ManyToOne(() => Supplier, (supplier) => supplier.msbSimpleManages)
  @JoinColumn({ name: 'supplier' })
  supplier: Supplier;

  @ManyToOne(() => ProductInfo, (productinfo) => productinfo.msbmanages)
  @JoinColumn({
    name: 'productuniquecode',
    referencedColumnName: 'productuniquecode',
  })
  productinfo: ProductInfo;

  // 一对多关联到customer_simple_child
  @OneToMany(
    () => CustomerSimpleChild,
    (customerSimpleChild) => customerSimpleChild.msbSimpleManage,
  )
  customersimplechild: CustomerSimpleChild[];
}
